home *** CD-ROM | disk | FTP | other *** search
/ Aminet 28 / Aminet 28 (1998)(GTI - Schatztruhe)[!][Dec 1998].iso / Aminet / dev / lang / fpc09905c.lha / fpc / units / dos.pp < prev    next >
Text File  |  1998-09-21  |  51KB  |  1,782 lines

  1. {
  2.     $Id: dos.pp,v 1.9 1998/09/14 20:20:57 carl Exp $
  3.     This file is part of the Free Pascal run time library.
  4.     Copyright (c) 1998 by Nils Sjoholm and Carl Eric Codere
  5.     members of the Free Pascal development team
  6.       Date conversion routine taken from SWAG
  7.  
  8.     See the file COPYING.FPC, included in this distribution,
  9.     for details about the copyright.
  10.  
  11.     This program is distributed in the hope that it will be useful,
  12.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  14.  
  15.  **********************************************************************}
  16.  
  17. Unit Dos;
  18.  
  19.  
  20. {--------------------------------------------------------------------}
  21. { LEFT TO DO:                                                        }
  22. {--------------------------------------------------------------------}
  23. { o DiskFree / Disksize don't work as expected                       }
  24. { o Implement SetDate and SetTime                                    }
  25. { o Implement EnvCount,EnvStr                                        }
  26. { o FindFirst should only work with correct attributes               }
  27. {--------------------------------------------------------------------}
  28.  
  29.  
  30.  
  31.  
  32. Interface
  33.  
  34. {$I os.inc}
  35.  
  36.  
  37. Const
  38.   {Bitmasks for CPU Flags}
  39.   fcarry     = $0001;
  40.   fparity    = $0004;
  41.   fauxiliary = $0010;
  42.   fzero      = $0040;
  43.   fsign      = $0080;
  44.   foverflow  = $0800;
  45.  
  46.   {Bitmasks for file attribute}
  47.   readonly  = $01;
  48.   hidden    = $02;
  49.   sysfile   = $04;
  50.   volumeid  = $08;
  51.   directory = $10;
  52.   archive   = $20;
  53.   anyfile   = $3F;
  54.  
  55.   {File Status}
  56.   fmclosed = $D7B0;
  57.   fminput  = $D7B1;
  58.   fmoutput = $D7B2;
  59.   fminout  = $D7B3;
  60.  
  61.  
  62. Type
  63.   ComStr  = String[255];  { size increased to be more compatible with Unix}
  64.   PathStr = String[255];  { size increased to be more compatible with Unix}
  65.   DirStr  = String[255];  { size increased to be more compatible with Unix}
  66.   NameStr = String[255];  { size increased to be more compatible with Unix}
  67.   ExtStr  = String[255];  { size increased to be more compatible with Unix}
  68.  
  69.  
  70.  
  71. {
  72.   filerec.inc contains the definition of the filerec.
  73.   textrec.inc contains the definition of the textrec.
  74.   It is in a separate file to make it available in other units without
  75.   having to use the DOS unit for it.
  76. }
  77. {$i filerec.inc}
  78. {$i textrec.inc}
  79.  
  80.  
  81. Type
  82.  
  83.   SearchRec = Packed Record
  84.     { watch out this is correctly aligned for all processors }
  85.     { don't modify.                                          }
  86.     { Replacement for Fill }
  87. {0} AnchorPtr : Pointer;    { Pointer to the Anchorpath structure }
  88. {4} Fill: Array[1..15] of Byte; {future use}
  89.     {End of replacement for fill}
  90.     Attr : BYTE;        {attribute of found file}
  91.     Time : LongInt;     {last modify date of found file}
  92.     Size : LongInt;     {file size of found file}
  93.     Name : String[255]; {name of found file}
  94.   End;
  95.  
  96.  
  97.   DateTime = packed record
  98.     Year: Word;
  99.     Month: Word;
  100.     Day: Word;
  101.     Hour: Word;
  102.     Min: Word;
  103.     Sec: word;
  104.   End;
  105.  
  106.  
  107.  
  108. Var
  109.   DosError : integer;
  110.  
  111. {Interrupt}
  112. {Procedure Intr(intno: byte; var regs: registers);
  113. Procedure MSDos(var regs: registers);}
  114.  
  115. {Info/Date/Time}
  116. Function  DosVersion: Word;
  117. Procedure GetDate(var year, month, mday, wday: word);
  118. Procedure GetTime(var hour, minute, second, sec100: word);
  119. procedure SetDate(year,month,day: word);
  120. Procedure SetTime(hour,minute,second,sec100: word);
  121. Procedure UnpackTime(p: longint; var t: datetime);
  122. Procedure PackTime(var t: datetime; var p: longint);
  123.  
  124. {Exec}
  125. Procedure Exec(const path: pathstr; const comline: comstr);
  126. Function  DosExitCode: word;
  127.  
  128. {Disk}
  129. Function  DiskFree(drive: byte) : longint;
  130. Function  DiskSize(drive: byte) : longint;
  131. Procedure FindFirst(path: pathstr; attr: word; var f: searchRec);
  132. Procedure FindNext(var f: searchRec);
  133. Procedure FindClose(Var f: SearchRec);
  134.  
  135. {File}
  136. Procedure GetFAttr(var f; var attr: word);
  137. Procedure GetFTime(var f; var time: longint);
  138. Function  FSearch(path: pathstr; dirlist: string): pathstr;
  139. Function  FExpand(path: pathstr): pathstr;
  140. Procedure FSplit(path: pathstr; var dir: dirstr; var name: namestr; var ext: extstr);
  141.  
  142. {Environment}
  143. Function  EnvCount: longint;
  144. Function  EnvStr(index: integer): string;
  145. Function  GetEnv(envvar: string): string;
  146.  
  147. {Misc}
  148. Procedure SetFAttr(var f; attr: word);
  149. Procedure SetFTime(var f; time: longint);
  150. Procedure GetCBreak(var breakvalue: boolean);
  151. Procedure SetCBreak(breakvalue: boolean);
  152. Procedure GetVerify(var verify: boolean);
  153. Procedure SetVerify(verify: boolean);
  154.  
  155. {Do Nothing Functions}
  156. Procedure SwapVectors;
  157. Procedure GetIntVec(intno: byte; var vector: pointer);
  158. Procedure SetIntVec(intno: byte; vector: pointer);
  159. Procedure Keep(exitcode: word);
  160.  
  161. implementation
  162.  
  163. const
  164.   DaysPerMonth :  Array[1..12] of ShortInt =
  165. (031,028,031,030,031,030,031,031,030,031,030,031);
  166.   DaysPerYear  :  Array[1..12] of Integer  =
  167. (031,059,090,120,151,181,212,243,273,304,334,365);
  168.   DaysPerLeapYear :    Array[1..12] of Integer  =
  169. (031,060,091,121,152,182,213,244,274,305,335,366);
  170.   SecsPerYear      : LongInt  = 31536000;
  171.   SecsPerLeapYear  : LongInt  = 31622400;
  172.   SecsPerDay       : LongInt  = 86400;
  173.   SecsPerHour      : Integer  = 3600;
  174.   SecsPerMinute    : ShortInt = 60;
  175.   TICKSPERSECOND    = 50;
  176.  
  177.  
  178.  
  179. Type
  180.     pClockData = ^tClockData;
  181.     tClockData = packed Record
  182.       sec   : Word;
  183.       min   : Word;
  184.       hour  : Word;
  185.       mday  : Word;
  186.       month : Word;
  187.       year  : Word;
  188.       wday  : Word;
  189.     END;
  190.  
  191.     BPTR     = Longint;
  192.     BSTR     = Longint;
  193.  
  194.   pMinNode = ^tMinNode;
  195.   tMinNode = Packed Record
  196.     mln_Succ,
  197.     mln_Pred  : pMinNode;
  198.   End;
  199.  
  200.  
  201.     pMinList = ^tMinList;
  202.     tMinList = Packed record
  203.     mlh_Head        : pMinNode;
  204.     mlh_Tail        : pMinNode;
  205.     mlh_TailPred    : pMinNode;
  206.     end;
  207. { *  List Node Structure.  Each member in a list starts with a Node * }
  208.  
  209.   pNode = ^tNode;
  210.   tNode = Packed Record
  211.     ln_Succ,                { * Pointer to next (successor) * }
  212.     ln_Pred  : pNode;       { * Pointer to previous (predecessor) * }
  213.     ln_Type  : Byte;
  214.     ln_Pri   : Shortint;        { * Priority, for sorting * }
  215.     ln_Name  : PCHAR;       { * ID string, null terminated * }
  216.   End;  { * Note: Integer aligned * }
  217.  
  218.  
  219.  
  220.     pList = ^tList;
  221.     tList = Packed record
  222.     lh_Head     : pNode;
  223.     lh_Tail     : pNode;
  224.     lh_TailPred : pNode;
  225.     lh_Type     : Byte;
  226.     l_pad       : Byte;
  227.     end;
  228.  
  229.  
  230.    pMsgPort = ^tMsgPort;
  231.     tMsgPort = Packed record
  232.     mp_Node     : tNode;
  233.     mp_Flags    : Byte;
  234.     mp_SigBit   : Byte;     { signal bit number    }
  235.     mp_SigTask  : Pointer;   { task to be signalled (TaskPtr) }
  236.     mp_MsgList  : tList;     { message linked list  }
  237.     end;
  238.  
  239.  
  240.   pTask = ^tTask;
  241.     tTask = Packed record
  242.         tc_Node         : tNode;
  243.         tc_Flags        : Byte;
  244.         tc_State        : Byte;
  245.         tc_IDNestCnt    : Shortint;         { intr disabled nesting         }
  246.         tc_TDNestCnt    : Shortint;         { task disabled nesting         }
  247.         tc_SigAlloc     : longint;        { sigs allocated                }
  248.         tc_SigWait      : longint;         { sigs we are waiting for       }
  249.         tc_SigRecvd     : longint;         { sigs we have received         }
  250.         tc_SigExcept    : longint;         { sigs we will take excepts for }
  251.         tc_TrapAlloc    : Word;        { traps allocated               }
  252.         tc_TrapAble     : Word;        { traps enabled                 }
  253.         tc_ExceptData   : Pointer;      { points to except data         }
  254.         tc_ExceptCode   : Pointer;      { points to except code         }
  255.         tc_TrapData     : Pointer;      { points to trap data           }
  256.         tc_TrapCode     : Pointer;      { points to trap code           }
  257.         tc_SPReg        : Pointer;      { stack pointer                 }
  258.         tc_SPLower      : Pointer;      { stack lower bound             }
  259.         tc_SPUpper      : Pointer;      { stack upper bound + 2         }
  260.         tc_Switch       :